<?php //echo "<pre>"; print_r($pBerkas);die();?>
<?php $this -> load -> view('header'); ?>
<!-- BEGIN CONTAINER -->
<div class="page-container row-fluid">
	<?php //$this->load->view('sidebar');?>
	<!-- BEGIN PAGE -->
	<div class="page-content">
		<!-- BEGIN SAMPLE PORTLET CONFIGURATION MODAL FORM-->
		<div id="portlet-config" class="modal hide">
			<div class="modal-header">
				<button data-dismiss="modal" class="close" type="button"></button>
				<h3>portlet Settings</h3>
			</div>
			<div class="modal-body">
				<p>
					Here will be a configuration form
				</p>
			</div>
		</div>
		<!-- END SAMPLE PORTLET CONFIGURATION MODAL FORM-->
		<!-- BEGIN PAGE CONTAINER-->
		<div class="container-fluid">
			<!-- BEGIN PAGE HEADER-->
			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN STYLE CUSTOMIZER -->
					<!--
					<div class="color-panel hidden-phone">
						<div class="color-mode-icons icon-color"></div>
						<div class="color-mode-icons icon-color-close"></div>
						<div class="color-mode">
							<p>
								THEME COLOR
							</p>
							<ul class="inline">
								<li class="color-black current color-default" data-style="default"></li>
								<li class="color-blue" data-style="blue"></li>
								<li class="color-brown" data-style="brown"></li>
								<li class="color-purple" data-style="purple"></li>
								<li class="color-white color-light" data-style="light"></li>
							</ul>
							<label class="hidden-phone">
								<input type="checkbox" class="header" checked value="" />
								<span class="color-mode-label">Fixed Header</span> </label>
						</div>
					</div> -->
					<!-- END BEGIN STYLE CUSTOMIZER -->

					<!-- BEGIN PAGE TITLE & BREADCRUMB-->
					<h3 class="page-title"> Daftar Laporan</h3>
					<?php $this -> load -> view('breadcrumb'); ?>
					<!-- END PAGE TITLE & BREADCRUMB-->
				</div>
			</div>
			<!-- END PAGE HEADER-->
			<!-- BEGIN PAGE CONTENT-->
			<div class="row-fluid">
				<div class="span12">
					<!-- BEGIN EXAMPLE TABLE PORTLET-->
					<div class="portlet box blue">
						<div class="portlet-title">
							<h4><i class="icon-edit"></i></h4>
							<!--<div class="tools" >
								<a href="javascript:;" class="reload"></a>
							</div>-->
														
							<div class="actions" style="padding-right: 0px">
								<?php 
									if ($selectedProfile == 6 || $selectedProfile == 10){ ?>
								<a href="<?php echo base_url().'inbox/createEdit/'.$selectedProfile ?>" class="btn green"><i class="icon-plus"></i> Tambah Laporan</a>
								<?php } ?>								
								<!--<a href="#" class="btn green"><i class="icon-print"></i> Print</a>
								<a href="#" class="btn green"><i class="icon-tasks"></i> Pdf</a>
								<a href="#" class="btn green"><i class="icon-envelope"></i> Excel</a> -->								
							</div>
							
						</div>
						<div class="portlet-body">
							<?php //$this->load->view('searchBar', $searchBar);?>
							<table class="table table-striped table-hover table-bordered" >
								<thead>
									<tr>
										<th align="center">No</th>
										<!--<th align="center">Kode Laporan</th>-->
										<th class="center">Nama Perpustakaan</th>
										<th class="center">Jenis Laporan</th>
										<th class="center">Rincian Laporan</th>
										<th class="center">Tanggal Pelaporan</th>
										
										<!--<th>Last Comment</th>-->
										<th class="center">Status</th> 
										<th class="center">Tindakan</th>
									</tr>
								</thead>
								<tbody>
								<?php
									$i=1; 
									foreach ($pBerkas['data'] as $berkas){ ?>
									<tr >
										<td><?php echo $i;?></td>
										<!--<td style="text-align: center;"><?php echo $berkas->getId();?></td>-->
										<td style="text-align: left;"><?php echo $berkas->getPerpustakaan()->getNama();?></td>
										<td style="text-align: left;"><?php 
											/*	 if ($berkas->getTipe()->getId() == "TRAINING"){
													  $criteria = array("id" => $berkas);	
													  $berkasTraining = $this -> em -> getRepository('\models\entities\BerkasTraining')->findOneBy($criteria);
													  echo $berkas->getTipe()->getNama(). " - " . $berkasTraining->getJenisTraining()->getNama();	
												  } else {
												  	  echo $berkas->getTipe()->getNama();	 
												  } */
											echo $berkas->getTipe()->getNama();
											?></td>
										<td style="text-align: left;"><?php 
												 if ($berkas->getTipe()->getId() == "TRAINING"){
													 // $criteria = array("id" => $berkas);	
													 // $berkasTraining = $this -> em -> getRepository('\models\entities\BerkasTraining')->findOneBy($criteria);
													 if ($berkas->getBerkasTraining()->getJenisTraining() != null){
													 	echo $berkas->getBerkasTraining()->getJenisTraining()->getNama();	
													 } 													  	
												  } else if ($berkas->getTipe()->getId() == "LKPM"){
												  	 if ($berkas->getBerkasLkpm()->getJenisKegiatan() != null){
												  	 	echo $berkas->getBerkasLkpm()->getJenisKegiatan()->getNama();	
												  	 }												  	  	 
												  } else if ($berkas->getTipe()->getId() == "LAS"){
												  	if ($berkas->getBerkasLas()->getJenisAsistensi() != null){
												  		if ($berkas->getBerkasLas()->getJenisAsistensi() == 1){
												  	  	$pre = "NON KUNJUNGAN";
												  	  } else {
												  	  	$pre = "KUNJUNGAN";
												  	  }
													  if ($berkas->getBerkasLas()->getKategoriAsistensi() != NULL){
													  	$pre .= " - " .$berkas->getBerkasLas()->getKategoriAsistensi()->getNama();
													  }
													  echo $pre;
												  	  //echo $pre." - ".$berkas->getBerkasLas()->getKategoriAsistensi()->getNama();	
												  	}												  	  	 
												  }  
											
											?></td>
										<td class="center"><?php echo ($berkas->getStartDate() != NULL) ? $berkas->getStartDate()->format('d-m-Y') : "";?></td>
										<td>
											<?php if ($berkas->getInbox()->getCondition() == "NOK"){
														echo '<span class="label label-important">Butuh Perbaikan</span>';
												  } 													
												  else {
												  		echo '<span class="label label-success">Laporan</span>';
												  		//echo '<span class="label label-success">'.$berkas->getInbox()->getCondition().'</span>';
												  }
												  		
											?></td>
										
									<!--	<td></td> -->
										<td>
											<a class="btn blue mini" href="<?php echo base_url().'inbox/createEdit/'.$selectedProfile."/".$berkas->getId()?>">Edit</a>&nbsp;
											<!--<a class="btn green mini" href="#" id="submitBtn" onclick="submitReport(event,'<?php echo $berkas->getId();?>','<?php echo $berkas->getInbox()->getCondition()?>')">Submit</a>&nbsp;-->
											<a class="btn red mini" href="" onclick="cancelReport(event,'<?php echo $selectedProfile."','".$berkas->getId();?>')">Hapus</a>
										</td>
									</tr>		
								<?php	$i++;} ?>
								</tbody>
							</table>
							<div class="row-fluid">
								<?php $this->load->view('paging', $pBerkas);?>
							</div>
						</div>
					</div>
					<!-- END EXAMPLE TABLE PORTLET-->
				</div>
			</div>
			<!-- END PAGE CONTENT -->
		</div>
		<!-- END PAGE CONTAINER-->
	</div>
	<!-- END PAGE -->
</div>
<!-- END CONTAINER -->
<div style="display: none">
	<form action="" method="post" id="formReport">
		<input type="hidden" name="id" id="inputId"/>
		<input type="hidden" name="Profile.id" id="inputProfile" value="<?php echo $selectedProfile?>"/>
		<input type="hidden" name="BerkasComment.text" id="berkasNote"/>
	</form>
</div>

<!-- DIALOG -->
<div id="myNote" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
		<h3 id="myModalLabel1">Add Comment</h3>		
	</div>
<div class="modal-body">
	<div class="portlet-body fuelux">
		<textarea id="note"></textarea>	
	</div>	
</div>
	<div class="modal-footer">
		<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
		<button class="btn yellow" id="saveNote">Save</button>
	</div>
</div>
<!-- END DIALOG -->

<div id="cancelModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel3" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
		<h3 id="myModalLabel3"></h3>
	</div>
	<div class="modal-body">
		<p>Apakah anda ingin menghapus laporan ini ?</p>				
	</div>
	<div class="modal-footer">
		<button class="btn" data-dismiss="modal" aria-hidden="true">Tidak</button>
		<button data-dismiss="modal" class="btn blue" id="confirmCancelBtn">Ya</button>
	</div>
</div>	

<div id="alertModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel2" aria-hidden="true">
	<div class="modal-header">
		<button type="button" class="close" data-dismiss="modal" aria-hidden="true"></button>
		<h3 id="myModalLabel2">Informasi</h3>
	</div>
	<div class="modal-body" id="alertMessage">
		
	</div>
	<div class="modal-footer">
		<button data-dismiss="modal" class="btn green">OK</button>
	</div>
</div>
<?php $this->load->view('footer')?>

<script>
	$(document).ready(function() {
		
		$("#alertModal").draggable({
      		handle: ".modal-header"
  		});
		
		//$('#alertModal').modal('show');
		<?php
			$flash_message = $this->session->userdata('flash_message');
			if ($flash_message != ""){
				echo "$('#alertMessage').html('<p>".$flash_message."</p>');
					  $('#alertModal').modal('show');
					 ";
				$this->session->set_userdata('flash_message',"");
			} 
		?>
		var cancelUrl = "";
		submitReport = function(event, id, status){
			event.preventDefault();
			$('#inputId').val(id);
			if (status=="NOK"){
				$('#myNote').modal('show');	
			} else {
				$('#formReport').attr('action', "<?php echo base_url()?>inbox/submit").submit();	
			}	  		
	  	};
	  	
	  	cancelReport = function(event, profileId, berkasId){
			event.preventDefault();
			cancelUrl = '<?php echo base_url()."inbox/cancelReport/"?>'+profileId+'/'+berkasId;
			$('#cancelModal').modal('show');			
	  	};
	  	
	  	$('#confirmCancelBtn').click(function(){
	  		window.location = cancelUrl;
	  	});
	  	
	  	$('#saveNote').click(function(){
			var textNote = $('#note').val();
			$('#berkasNote').val(textNote);
			if (textNote==''){
				alert('Harus input comment');
				return;
			} else {
				$('#myNote').modal('hide');
				$('#formReport').attr('action', "<?php echo base_url()?>inbox/submit").submit();
			}			
		});
	});
</script>